package com.alstudio.ui.module.user;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.module.xmpp.request.ALUiXmppRequestCreator;
import com.alstudio.pojo.ALXmppEvent;
import com.alstudio.ui.base.TitleBarActivity;
import com.loovee.imaohu.R;

public class EmailSendDetail extends TitleBarActivity {

	private static final String TAG = "EmailSendDetail";

	private String email;
	private TextView email_send_detail;
	private Button email_send_again, email_modify;
	private Context mContext;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setupView(this, getClass().getSimpleName());
		initData();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#setupView(android.content.Context,
	 * java.lang.String)
	 */
	@Override
	protected void setupView(Context context, String name) {
		super.setupView(context, name);
		setTitleBarContentView(R.layout.bind_email1);
		setCenterTextViewMessage(R.string.TxtEmailBind);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.BaseActivity#initData()
	 */
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		email = getIntent().getStringExtra("email");
		initUI();
	}

	private void initUI() {
		email_modify = (Button) findViewById(R.id.email_modify);
		email_send_again = (Button) findViewById(R.id.email_send_again);
		email_send_detail = (TextView) findViewById(R.id.email_send_detail);
		String text = getString(R.string.TxtEmailSendDetail).replace("%$s",
				ALLocalEnv.getLocalEnv().getMyProfile().getEmail());
		email_send_detail.setText(text);
		email_modify.setOnClickListener(this);
		email_send_again.setOnClickListener(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.ui.base.TitleBarActivity#onClick(android.view.View)
	 */
	@Override
	public void onClick(View v) {
		super.onClick(v);
		switch (v.getId()) {
		case R.id.email_send_again:
			sendRebind();
			break;
		case R.id.email_modify:
			showBindEmail();
			finish();
			break;
		}
	}

	// public void bindEmailSuceess() {
	// if (!isFinishing() || mContext != null) {
	// MyToastUtil.getInstance().showToastOnCenter(
	// App.ctx.getString(R.string.string_email_sucees));
	// App.myVcard.setEmailIsBind(1);
	// this.finish();
	// }
	// }

	private void sendRebind() {
		if (ALLocalEnv.isSendXmppDataEnable()) {
			ALUiXmppRequestCreator.postALUiXmppBindEmailAgain();
			showLoadingProgress();
		}
	}

	/**
	 * 进入填写邮箱页面
	 */
	private void showBindEmail() {
		Intent intent = new Intent();
		intent.setClass(EmailSendDetail.this, EmailBind.class);
		startActivity(intent);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.ui.base.BaseActivity#handleBindEmailAaginResult(com.alstudio
	 * .pojo.ALXmppEvent)
	 */
	@Override
	public void handleBindEmailAaginResult(ALXmppEvent data) {
		// TODO Auto-generated method stub
		super.handleBindEmailAaginResult(data);
		dismissLoadingProgress();
	}

}
